<?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

if (!function_exists('jawaban')) {
    function jawaban($id_soal, $id_jenis_soal, $urut) {
        $CI = & get_instance();
        $CI->load->database();

        $CI->db->select('id_jwb_soal, jawaban');
        $CI->db->where('id_soal', $id_soal);
        $CI->db->order_by('rand()');
        $query = $CI->db->get('jawaban_soal');

        if ($query->num_rows() > 0) {
            $result = $query->result_array();            
            $query->free_result();
        } else {
            $result = array();
        }

        if (!empty($result) && $id_jenis_soal == 1 && !empty($result)) {
            foreach ($result as $jawaban) {
                echo '<div class="radio">';
                    echo '<label>';
                    echo '<input type="radio" name="jawaban-'.$urut.'" value="'.$jawaban['id_jwb_soal'].'" class="jawaban">';
                        echo $jawaban['jawaban'];
                    echo '</label>';
                echo '</div>';
            }
        }elseif(!empty($result) && $id_jenis_soal == 2){
            foreach ($result as $jawaban) {
                echo '<div class="checkbox">';
                    echo '<label>';
                    echo '<input type="checkbox" name="jawaban-'.$urut.'" value="'.$jawaban['id_jwb_soal'].'">';
                        echo $jawaban['jawaban'];
                    echo '</label>';
                echo '</div>';
            }
        }elseif(!empty($result) && $id_jenis_soal == 3){
            foreach ($result as $jawaban) {
                echo '<div class="radio">';
                    echo '<label>';
                    echo '<input type="radio" name="jawaban-'.$urut.'" value="'.$jawaban['id_jwb_soal'].'" class="jawaban">';
                        echo $jawaban['jawaban'];
                    echo '</label>';
                echo '</div>';
            }
        }elseif(!empty($result) && $id_jenis_soal == 4){
            
        }elseif(!empty($result) && $id_jenis_soal == 5){
            
        }else{
            echo '';
        }

    }
}

if (!function_exists('jawaban_challenge')) {
    function jawaban_challange($id_soal, $urut, $challenge) {
        $CI = & get_instance();
        $CI->load->database();

        $sql = 'SELECT * FROM jawaban_soal WHERE id_soal = '.$id_soal.' ORDER BY rand()';
        $query = $CI->db->query($sql);

        if ($query->num_rows() > 0) {
            $result = $query->result_array();            
            $query->free_result();
        } else {
            $result = array();
        }

        foreach ($result as $jawaban) {
            echo '<div class="radio">';
                echo '<label>';
                echo '<input type="radio" name="soal'.$urut.'" id="soal'.$urut.'" value="'.$jawaban['id_jwb_soal'].'" class="jawaban'.$challenge.'" onClick="check('.$urut.','.$jawaban['id_jwb_soal'].')">';
                    echo $jawaban['jawaban'];
                echo '</label>';
            echo '</div>';
        }
        echo '<input type="hidden" name="jawaban'.$urut.'" id="jawaban'.$urut.'">';
    }
}
